package com.bweab.dao.impl;

import com.bweab.dao.api.DormitoryTbDaoInterface;
import com.bweab.dao.base.BaseDao;
import com.bweab.pojo.DormitoryTb;
/**
 * 宿舍信息查询
 * */
public class DormitoryTbDaoImpl extends BaseDao<DormitoryTb> implements DormitoryTbDaoInterface {


    //定义影响函数变量
    int rows;
    /**
     *
     * @param dormitoryName 寝室名字
     * @return 返回寝室信息
     */

    @Override
    public DormitoryTb getDormitoryInfo(String dormitoryName) {
        //准备sql语句
        String sql="select\n" +
                "    dormitory_id dormitoryId,\n" +
                "    dormitory_name dormitoryName,\n" +
                "    dormitory_monkey dormitoryMonkey\n" +
                "from\n" +
                "    dormitory_tb\n" +
                "where dormitory_name=?";

        DormitoryTb dormitoryInfo = querySingle(sql, DormitoryTb.class, dormitoryName);
        return dormitoryInfo;
    }


    /**
     * @param dormitoryname   寝室名字
     * @param dormitorymonkey 寝室水电费金钱
     * @param dormitoryid
     * @return 返回结果为影响的行数
     */

    @Override
    public int alterDormitoryInfo(String dormitoryname, int dormitorymonkey, int dormitoryid) {

        //准备sql
        String sql="update dormitory_tb " +
                "set " +
                "dormitory_name=?, " +
                "dormitory_monkey=?" +
                " where " +
                "dormitory_id =?";

        //调用alter
        int rows = alter(sql, dormitoryname,dormitorymonkey,dormitoryid);

        return rows;
    }


    /**
     *
     * @param dormitoryName 寝室名字
     * @param dormitoryFee  寝室费用
     * @return 1成功 0 失败
     */
    @Override
    public int addDormitoryInfo(String dormitoryName, int dormitoryFee) {
        //准备sql
        String sql="insert into dormitory_tb values\n" +
                "                             (default,\n" +
                "                              ?,\n" +
                "                              ?\n" +
                "                             )";


        // 第一个参数是寝室名字，第二个名字是寝室的费用
        int rows= alter(sql,dormitoryName,dormitoryFee);
        return rows;
    }

    /**
     *
     * @param dormitoryname 寝室名字
     * @return  返回结果为1 成功 0 失败
     */
    @Override
    public int deleteDormitoryInfo(String dormitoryname) {
        //准备sql语句
        String sql="delete from dormitory_tb where dormitory_name=?";

        int rows=alter(sql,dormitoryname);
        return rows;
    }
}
